#!/usr/bin/perl
#setpass-lib.pl
#Library for editing webmin users, password and access rights

do '../web-lib.pl';

&init_config();
%access = &get_module_acl();

#get_telnet_status(void)
#return $rt_status,   if telnet is started, $rt_status = 'started', else telnet is stopped , $tr_status='stopped'
sub get_iet_status()
{
	my (@file, $i, @line, $rt, @out, $xinet_stat);

	$xinet_stat = 0;

	@out = `lsmod|grep 'iscsi_trgt'`;


	for($i = 0; $i < @out; $i++)
	{
		if($out[$i] =~ /iscsi_trgt/)
		{
			$xinet_stat = 1;
			last;
		}
	}

	return 'stopped' if($xinet_stat == 0);

	return 'started';
}

#operate_telnetserv($oper)
#oper is operation for telnet service
sub operate_ietserv()
{
	my (@file, $i, @line, $oper, $strline, $disable, @out, $iet_stat);

	$oper = @_[0];

	@out = `lsmod|grep iscsi_trgt`;
	$iet_stat = 0;

	for($i = 0; $i < @out; $i++)
	{
		if($out[$i] =~ /iscsi_trgt/)
		{
			$iet_stat = 1;
			last;
		}
	}

	if($iet_stat) 
	{
	   if($oper =~ /stop/)
	   {
		`/etc/init.d/iscsi-target stop`;
	   }
	}
	else 
	{
	   if($oper =~ /start/)
	   {
		`/etc/init.d/iscsi-target start`;
	   }
	}
}

sub get_gstr()
{
	open(FH, "/etc/ietd.conf");
	@ietd = <FH>;
	close(FH);
	$num = @ietd;
	#for($i=0; $i<@num; $i++)
	#{
		#$ietd[$i] =~ s/#.*$//;
		if($ietd[0] =~ /^#\s(\S+)/)
		{
			return $1;
		}  
	#}
}

sub get_session_status()
{
   open(FS, "/proc/net/iet/session");
   @sess=<FS>;
   close(FS);
   $num=@sess;
   for($i=0; $i<$num; $i++) {
        $sess[$i] =~ s/\r|\n//g;
        if($sess[$i] =~ /^tid:\d+\s+name:/) {
                   return 1;
        }
   }
   return 0;
}
sub change_gstr()
{

}
1;
